(function () {
  const backtotop = document.getElementById('backtotop')
  let timer;
  backtotop.onclick = function () {
    clearInterval(timer)
    timer = setInterval(function () {
      document.documentElement.scrollTop -= 100

      if (document.documentElement.scrollTop <= 0) {
        clearInterval(timer)
      }
    }, 20)
  }

  //监听页面的滚动
  window.onscroll = function () {
    //卷东值
    let scrollTop = document.documentElement.scrollTop || window.scrollY;

    if (scrollTop === 0) {
      backtotop.style.display = 'none'
    } else {
      backtotop.style.display = 'block'
    }
  }
})();